﻿@using E5_KhuyenMaiVang.Models;
@model IEnumerable<E5_KhuyenMaiVang.Models.DEAL>

@{
    ViewBag.Title = "Home";
}
@{
    DEAL firstDeal = null;
    if(Model.Count() !=0){
        Random random = new Random();
        int randNum = random.Next(Model.Count());
        firstDeal = Model.ElementAt(randNum);
    }
    var TimeCount = 1;
}

@if (firstDeal != null)
{
<div id="random_deal">
    <table width="100%">
        <tr>
            <td>
                <a href="@Url.Action("Detail", "Produce", new { dealID = @firstDeal.DealID })">
                <img src="@firstDeal.Image" alt="@firstDeal.Description" title="@firstDeal.Description"width="404" />
                </a>
            </td>
            <td valign="top">
                <h3><a href="@Url.Action("Detail", "Produce", new { dealID = @firstDeal.DealID })" title="@firstDeal.DealName">@firstDeal.DealName</a></h3>
                <br />
                <h4>@firstDeal.Description</h4>
                <br />
                <table width="100%">
                    <tr>
                        <td align="left">
                            <div class="addr_deals">
                                <span>
                                    <img src="http://khuyenmaivang.vn/layout/images/home-icon.jpg" alt="" />
                                    14A, Sông Đà, P.2, Q.Tân Bình, Tp.HCM </span>
                            </div>
                        </td>
                        <td align="right">
                            <div class="addr_deals">
                                <span>
                                    <img src="http://khuyenmaivang.vn/layout/images/voucher-icon.jpg" alt="" />
                                    Giao hàng tận nơi </span>
                            </div>
                        </td>
                    </tr>
                </table>
                <br />               
                <div id="random_deal_static2">
                    <span id="time_deal">
                        <img src="http://khuyenmaivang.vn/layout/images/clock-01.jpg" alt="" />
                        @{                            
    var firstDealTime = @firstDeal.EndDate.ToString("yyyy-M-d HH:mm:ss") + " GMT+00:00";
    var IDfirstDealTime = "countdown" + TimeCount++;
    
                        <p>Thời gian còn lại: <p id="@IDfirstDealTime">@firstDealTime</p></p>
                        }
                    </span><span id="count_buy">
                        <img src="http://khuyenmaivang.vn/layout/images/buycount-01.jpg" alt="" />
                        <p>Đã bán được @firstDeal.SoldQuantity deals.</p>
                    </span>
                </div>
                    
               
                <div class="random_deal_wrp prices_show">
                    <div id="price1">
                        Giá thị trường<br />
                        <span>@firstDeal.Price</span>
                    </div>
                    <div id="price2">
                        Giá Bán<br />
                        <span style="font-size: 15pt">@firstDeal.Discount</span>
                    </div>
                    <div id="rate_sale">
                        Tiết kiệm<br />
                        <span>@((int)((firstDeal.Discount * 100) / firstDeal.Price))%</span>
                    </div>
                    <div id="view-btn">
                        <a href="@Url.Action("Detail", "Produce", new { dealID = @firstDeal.DealID })" title="@firstDeal.DealName">Xem</a>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</div>
    }
else { 
    <div class="ui-widget">
			<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
				<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
				<strong>Alert:</strong> Không có sản phẩm nào.</p>
			</div>
		</div>
}
@foreach (var deal in Model)
{
    if (deal.DealID == firstDeal.DealID) { continue; } 
    var iddealTime = "countdown" + TimeCount;
    var dealTime = @deal.EndDate.ToString("yyyy-M-d HH:mm:ss") + " GMT+00:00";
    TimeCount++; 
    <div class="list_deals">
        <h2>
            <a href="@Url.Action("Detail", "Produce", new { dealID = @deal.DealID })"
                title="@deal.DealName">@deal.DealName</a>
        </h2>
        <div class="image_deals">
            <a href="@Url.Action("Detail", "Produce", new { dealID = @deal.DealID })"
                title="@deal.Description">
                <img src= "@deal.Image" alt="@firstDeal.Description" />
            </a>
        </div>
        <div class="addr_deals">
            <span>
                <img src="http://khuyenmaivang.vn/layout/images/voucher-icon.jpg" alt="" />
                Giao voucher </span>
        </div>
        <div class="price_deals">
            <div class="price_deals_left">
                Giá thị trường<br />
                <span>@deal.Price</span>
                <br />
                <span class="wrp-rate"><strong>Tiết kiệm</strong></span> <span class="rate-s">@((int)((deal.Discount * 100) / deal.Price))%</span>
            </div>
            <div class="price_deals_right">
                Giá Bán<br />
                <span>@deal.Discount</span>
                <br />
                <span class="count-b">Đã bán được @deal.SoldQuantity deal.</span>
            </div>
        </div>
        

        <div class="bottom_deals">
            <span class="timer">              
                   <p>Thời gian còn lại: <p id="@iddealTime">@dealTime</p></p>
            </span>
            <a href="@Url.Action("Detail", "Produce", new { dealID = @deal.DealID })" title="@deal.DealName">Xem</a>
        </div>
    </div>               
}
<table width="100%">
</table>
@if (firstDeal != null)
{
<div class="pagination">
    @for (int p = 1; p <= ViewBag.TotalPages; p++)
    {
        <a class="@(p == ViewBag.CurrentPage ? "current" : "")" href="@Url.Action("Index", "Home", new { page = p })">@p</a>
    }
</div>
}
<br />
